package com.nwcl.basic.service.impl;

import com.nwcl.basic.bo.UserRoleBO;
import com.nwcl.basic.dao.UserRoleDao;
import com.nwcl.basic.entity.UserRole;
import com.nwcl.basic.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author liguiqin
 * @date 2023/5/30
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {
    @Autowired
    private UserRoleDao userRoleDao;
    @Override
    public List<Integer> listByUserId(Integer userId) {
        List<Integer> roleIds=new ArrayList<>();
        List<UserRole> userRoles = userRoleDao.listByUserId(userId);
        if(CollectionUtils.isEmpty(userRoles)){
            return Collections.emptyList();
        }
        userRoles.forEach(userRole -> {
            roleIds.add(userRole.getRoleId());
        });
        return roleIds;
    }
}
